package cn.itcast.consumer.client;

import cn.itcast.consumer.pojo.User;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

/**
 * Feign利用SpringMVC的注解，获取请求信息：请求方式、请求参数、请求路径、返回值类型 \r
 * 然后Feign会帮我们发起远程调用请求，实现功能。
 *
 * @author 虎哥
 */
@FeignClient(value = "user-service", fallback = UserClient.UserClientFallback.class)
public interface UserClient {

    @GetMapping("/user/{id}")
    User queryById(@PathVariable("id") Long id);

    @Component
    class UserClientFallback implements UserClient {
        @Override
        public User queryById(Long id) {
            return new User();
        }
    }
}
